var UNPAY_DISK={
		initPage: function(){
			Ext.create('Ext.container.Viewport', {
			    layout: 'border',
			    frame:false,
			    border:false,
			    items: [{
			    	id: 'mainPanel',
			        region: 'center',
			        layout: 'fit',
			        items:[UNPAY_DISK.createCarGrid()]
			    }]
			});
		},
		createCarGrid: function(){
			var cargrid = Ext.create('Ext.com.bkfm.datagrid', {
				id: "car_checkin",
				objPath : "ROOT/YWGLPT/QCWX/V_BKFM_WXWFK",
				border: true,
				orderby : ' ORDER BY WXRQ DESC',
				customBtn: ['车牌号码',{
					xtype: 'textfield',
					id: 's_cphm',
					width: 100
				},'维修日期',{
					xtype: 'datefield',
					format: 'Y-m-d',
					width: 100,
					id: 's_wxrq_start'
				},'至',{
					xtype: 'datefield',
					format: 'Y-m-d',
					width: 100,
					id: 's_wxrq_end'
				},{
					text: '查询',
					iconCls: 'search',
					handler: function(){
						var s_cphm = Ext.getCmp("s_cphm").getValue();
						var s_wxrq_start = Ext.getCmp("s_wxrq_start").getRawValue();
						var s_wxrq_end = Ext.getCmp("s_wxrq_end").getRawValue();
						var filter = "";
						if(!Ext.isEmpty(s_cphm)){
							filter += " and cphm like '%"+Ext.util.Format.uppercase(s_cphm)+"%'";
						}
						if(!Ext.isEmpty(s_wxrq_start)){
							filter +=" and wxrq >='"+s_wxrq_start+"'";
						}
						if(!Ext.isEmpty(s_wxrq_end)){
							filter +=" and wxrq <='"+s_wxrq_end+"'";
						}
						Ext.getCmp("car_checkin").search(filter);
					}
				},'-',{
					text: '打印',
					iconCls: 'print',
					hidden: Utils.isHiddenCustomPageBtn("print"),
					handler: function(){
						var record = cargrid.getSelectedRecords();
						if(record.length>0){
							window.open(CONTEXT.contextPath+"/web/business/car/print.jsp?rwid="+record[0].getId())
						}else{
							AjaxUtils.showError("请选择需要打印的记录");
						}
					}
				}],
				afterFormShow: function(gridPanel,formTabPanel){
					var wxdbm = formTabPanel.items.get(0).getFormRwid();
					var disabled = true;
					if(formTabPanel.items.get(0).getFormState() == Constants.RECORD_CHANGED){
						disabled = false;
					}
					//维修项目
					formTabPanel.add(createXxxmgrid(formTabPanel,disabled,wxdbm));
					
					//配件维修清单
					formTabPanel.add(createWxxdgrid(formTabPanel,disabled,wxdbm));
				},
				beforeFormSave: function(gridPanel,formTabPanel){
					
				},
				afterFormSave: function(gridPanel,formTabPanel,win){
					var panel = formTabPanel.items.get(1);
					panel.setDisabled(false);
					panel.show();
					formTabPanel.items.get(1).setDisabled(false);
				}
			});
			//双击行记录
			cargrid.on("itemdblclick",function(view,record){
				/*var win = Ext.create('Ext.com.bkfm.window', {
					title : '维修车牌号：'+record.get("CPHM"),
					autoScroll : true,
					modal : true,
					items:[
						Ext.create('Ext.com.bkfm.datagrid', {
							id: "same_car",
							objPath : "ROOT/YWGLPT/QCWX/V_BKFM_WXWFK",
							border: 0,
							frame: false,
							orderby : ' ORDER BY WXRQ DESC',
							filter: " CPHM='"+record.get("CPHM")+"'",
							afterFormShow: function(gridPanel,formTabPanel){
								var wxdbm = formTabPanel.items.get(0).getFormRwid();
								var disabled = true;
								if(formTabPanel.items.get(0).getFormState() == Constants.RECORD_CHANGED){
									disabled = false;
								}
								//维修项目
								formTabPanel.add(createXxxmgrid(formTabPanel,disabled,wxdbm));
								
								//配件维修清单
								formTabPanel.add(createWxxdgrid(formTabPanel,disabled,wxdbm));
							},
							beforeFormSave: function(gridPanel,formTabPanel){
								
							},
							afterFormSave: function(gridPanel,formTabPanel,win){
								var panel = formTabPanel.items.get(1);
								panel.setDisabled(false);
								panel.show();
								formTabPanel.items.get(1).setDisabled(false);
							}
						})
					],
					maximized: true
				});
				win.show();*/
				var title = "车牌号："+record.get("CPHM") + " | 客户："+record.get("KHMC")+" | 电话："+record.get("DHHM")+" | 汽车品牌："+record.get("QCPP");
				Ext.create('Ext.com.bkfm.window', {
					title: title,
					autoScroll : true,
					modal : true,
					//maximized: true,
					width: Utils.getWidth()*0.98,
					height: Utils.getHeight()*0.98,
					layout: {
		                type: 'border'
		            },
		            items:[{
		            	region: 'west',
		            	width: Utils.getWidth()*0.4,
		                border: false,
		                layout: 'fit',
		                items:[Ext.create('Ext.com.bkfm.datagrid', {
							id: "same_car",
							objPath : "ROOT/YWGLPT/QCWX/V_BKFM_WXWFK",
							border: 0,
							frame: false,
							width:"100%",
							height: "100%",
							orderby : ' ORDER BY WXRQ DESC',
							filter: " CPHM='"+record.get("CPHM")+"'",
							afterFormShow: function(gridPanel,formTabPanel){
								var wxdbm = formTabPanel.items.get(0).getFormRwid();
								var disabled = true;
								if(formTabPanel.items.get(0).getFormState() == Constants.RECORD_CHANGED){
									disabled = false;
								}
								//维修项目
								formTabPanel.add(createXxxmgrid(formTabPanel,disabled,wxdbm));
								
								//配件维修清单
								formTabPanel.add(createWxxdgrid(formTabPanel,disabled,wxdbm));
							},
							beforeFormSave: function(gridPanel,formTabPanel){
								
							},
							afterFormSave: function(gridPanel,formTabPanel,win){
								var panel = formTabPanel.items.get(1);
								panel.setDisabled(false);
								panel.show();
								formTabPanel.items.get(1).setDisabled(false);
							},
							listeners:{
								itemclick: function(view,record){
									UNPAY_DISK.showDetialRecord(record);
								}
							},
							afterload: function(store,records){
								if(records.length>0){
									var record = records[0];
									Ext.getCmp("same_car").selectRecordById(record.getId());
									UNPAY_DISK.showDetialRecord(record);
								}
							}
						})]
		            },{
		            	region: 'center',
		            	border: false,
		            	layout: {
			                type: 'border'
			            },
			            items:[{
			            	region: 'south',
			            	height: Utils.getHeight()*0.3,
			                border: false,
			                layout: 'fit',
			                items:[Ext.create('Ext.com.bkfm.datagrid', {
								//title: "维修项目",
								id: "car_checkin_wxxm_detial",
								objPath : "ROOT/YWGLPT/QCWX/T_BKFM_WXXM",
								border: true,
								width:"100%",
								height: "100%",
								showstandardBtn: false,
								hiddenField: ['WXDBM'],
								paging: false,
								loadAuto: false,
								statistics: true,
								statisticsField:{
									JE:{
										summaryType: 'sum',
						                summaryRenderer: function (value, summaryData, dataIndex) {
						                	var value = Ext.util.Format.number(value, '0,000.00');
						                	Ext.get("total_price").dom.innerHTML = "<strong>维修项目->维修项目总金额：</strong>【<font color=red>"+value+"(元)</font>】"
						                	return "<strong>合计总金额：</strong>【<font color=red>"+value+"(元)</font>】";
						                }
									}
								},
								tbar:['<div id="total_price"></div>'],
							})]
			            },{
			            	region: 'center',
			            	height: Utils.getHeight()*0.7,
			                border: false,
			                layout: 'fit',
			                items:[Ext.create('Ext.com.bkfm.datagrid', {
								//title: "配件维修清单",
								id: "car_checkin_wxxd_detial",
								objPath : "ROOT/YWGLPT/QCWX/T_BKFM_WXPJQD",
								border: true,
								width:"100%",
								height: "100%",
								showstandardBtn: false,
								hiddenField: ['WXDBM'],
								paging: false,
								loadAuto: false,
								statistics: true,
								statisticsField:{
									JE:{
										summaryType: 'sum',
						                summaryRenderer: function (value, summaryData, dataIndex) {
						                	var value = Ext.util.Format.number(value, '0,000.00');
						                	Ext.get("qd_total_price").dom.innerHTML = "<strong>配件维修清单->维修清单总金额：</strong>【<font color=red>"+value+"(元)</font>】";
						                	return "<strong>合计总金额：</strong>【<font color=red>"+value+"(元)</font>】";
						                }
									}
								},
								tbar:['<div id="qd_total_price"></div>'],
							})]
			            }]
		            	
		            }]
				}).show();
			});
			
			return cargrid;
		},
		/**
		 * 展示详细信息
		 */
		showDetialRecord: function(record){
			Ext.getCmp("car_checkin_wxxm_detial").search(" WXDBM='"+record.getId()+"'");
			Ext.getCmp("car_checkin_wxxd_detial").search(" WXDBM='"+record.getId()+"'");
		}
};
Ext.onReady(function(){
	UNPAY_DISK.initPage();
});

/**
 * 项目清单
 * @returns
 */
function createXxxmgrid(formTabPanel,disabled,wxdbm){
	var wxxmgrid = Ext.create('Ext.com.bkfm.datagrid', {
		title: "维修项目",
		id: "car_checkin_wxxm",
		objPath : "ROOT/YWGLPT/QCWX/T_BKFM_WXXM",
		border: 0,
		frame: false,
		disabled: disabled,
		showstandardBtn: false,
		gridEditor: true,
		filter: " WXDBM='"+wxdbm+"'",
		hiddenField: ['WXDBM'],
		paging: false,
		statistics: true,
		statisticsField:{
			JE:{
				summaryType: 'sum',
                summaryRenderer: function (value, summaryData, dataIndex) {
                	var value = Ext.util.Format.number(value, '0,000.00');
                	return "<strong>合计总金额：</strong>【<font color=red>"+value+"(元)</font>】";
                }
			}
		},
		tbar:['->',{
			text: '新增',
			iconCls: 'add',
			handler: function(){
				var wxdbm = formTabPanel.items.get(0).getFormRwid();
				wxxmgrid.addNewRecord(function(record){
					record.set("WXDBM",wxdbm);
				})
			}
		},{
			text: '删除',
			iconCls: 'delete',
			handler: function(){
				wxxmgrid.deleteRecords();
			}
		},{
			text: '保存',
			iconCls: 'save',
			handler: function(){
				wxxmgrid.save();
			}
		}]
	});
	return wxxmgrid;
}
/**
 * 配件维修清单
 * @returns
 */
function createWxxdgrid(formTabPanel,disabled,wxdbm){
	var wxxdgrid = Ext.create('Ext.com.bkfm.datagrid', {
		title: "配件维修清单",
		id: "car_checkin_wxxd",
		objPath : "ROOT/YWGLPT/QCWX/T_BKFM_WXPJQD",
		border: 0,
		frame: false,
		disabled: disabled,
		showstandardBtn: false,
		gridEditor: true,
		filter: " WXDBM='"+wxdbm+"'",
		hiddenField: ['WXDBM'],
		paging: false,
		statistics: true,
		statisticsField:{
			JE:{
				summaryType: 'sum',
                summaryRenderer: function (value, summaryData, dataIndex) {
                	var value = Ext.util.Format.number(value, '0,000.00');
                	return "<strong>合计总金额：</strong>【<font color=red>"+value+"(元)</font>】";
                }
			}
		},
		tbar:['->',{
			text: '新增',
			iconCls: 'add',
			handler: function(){
				var wxdbm = formTabPanel.items.get(0).getFormRwid();
				wxxdgrid.addNewRecord(function(record){
					record.set("WXDBM",wxdbm);
				})
			}
		},{
			text: '删除',
			iconCls: 'delete',
			handler: function(){
				wxxdgrid.deleteRecords();
			}
		},{
			text: '保存',
			iconCls: 'save',
			handler: function(){
				wxxdgrid.save();
			}
		}]
	});
	return wxxdgrid;
}